package com.ymatou.iapi.userservice.testcase;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.userservice.parameter.BriefBatchUserRequestDtoBean;
import com.ymatou.iapi.userservice.parameter.enums.LoginNameEnum;
import com.ymatou.iapi.userservice.parameter.req.BriefBatchUserRequestDtoReq;
import com.ymatou.iapi.userservice.parameter.req.CreateUserReq;
import com.ymatou.iapi.userservice.parameter.resp.QueryBatchUserBriefNetResp;
import com.ymatou.iapi.userservice.service.BriefBatchUserRequestDtoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.database.model.Userinfo;
import com.ymttest.database.model.Userinfoex;
import com.ymttest.database.sqlwapper.JUserWapper;
import com.ymttest.utils.constant.ECode;

/**
 * 批量查询用户详细信息Test FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_BriefBatchUserRequestDto {
	private static BriefBatchUserRequestDtoBean briefbatchuserrequestdtoBean;
	private static BriefBatchUserRequestDtoCall briefbatchuserrequestdtoCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("批量查询用户详细信息Test");
	}

	@Before
	public void caseUp() {
		briefbatchuserrequestdtoBean = new BriefBatchUserRequestDtoBean();
		briefbatchuserrequestdtoCall = new BriefBatchUserRequestDtoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(briefbatchuserrequestdtoCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	private void verifyDB(BriefBatchUserRequestDtoCall b1) throws JSONException {
		JUserWapper ju = new JUserWapper();
		ArrayList<QueryBatchUserBriefNetResp> list = b1.getResult();

		for (QueryBatchUserBriefNetResp Result : list) {

			List<Userinfo> lui = ju.selectUserinfoByUid(Result.getUserId());
			Userinfo ui = lui.get(0);
			List<Userinfoex> lui2 = ju.selectUserinfoexByUid(Result.getUserId());
			Userinfoex uiex = lui2.get(0);

			Logger.comment("验证Userinfo");

			Logger.verifyEquals(Result.getUserId(), ui.getUserId(), "验证iUserId");
			Logger.verifyEquals(Result.getLoginId(), ui.getLoginId(), "验证sLoginId");
			Logger.verifyEquals(Result.getLoginMail(), ui.getLoginMail(), "验证sLoginEmail");
			Logger.verifyEquals(Result.getLoginMobile(), ui.getLoginMobile(), "验证sLoginMobile");
			Logger.verifyEquals(Result.getUserType().getCode(), ui.getUserType(), "验证iType");
			Logger.verifyEquals(Result.getUserState(), ui.getUserState(), "验证userState");

			Logger.comment("验证Userinfoex");
			Logger.verifyEquals(Result.getLogoUrl(), uiex.getLogoUrl(), "验证logUrl");
			Logger.verifyEquals(Result.getQq(), uiex.getQQ(), "验证qq");

		}

	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_BriefBatchUserRequestDto_001() {
		Logger.start(true, "批量查询多个用户详细信息,成功");
		try {
			List<String> LoginNameList = new ArrayList<>();
			for (int i = 0; i < 3; i++) {
				CreateUserReq cur = new CreateUserReq();
				cur = JUserCallService.initCreateUserBean(cur);
				Integer uid = JUserCallService.createUserCall(cur);
				String loginId = cur.getLoginId();
				LoginNameList.add(loginId);

			}

			briefbatchuserrequestdtoBean.setLoginNameList(LoginNameList);
			briefbatchuserrequestdtoBean.setLoginNameType(LoginNameEnum.LoginId);
			briefbatchuserrequestdtoCall.setData(briefbatchuserrequestdtoBean);
			briefbatchuserrequestdtoCall.callService();

			Logger.verifyEquals(ECode.SUCCESS, briefbatchuserrequestdtoCall.getString("ResponseCode"),
					"验证ResponseCode");
			Logger.verifyEquals("true", briefbatchuserrequestdtoCall.getString("Success"), "验证Success");

			verifyDB(briefbatchuserrequestdtoCall);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_BriefBatchUserRequestDto_002() {
		Logger.start(true, "批量查询单个用户详细信息,成功");
		try {
			List<String> LoginNameList = new ArrayList<>();
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);
			String loginId = cur.getLoginId();
			LoginNameList.add(loginId);

			briefbatchuserrequestdtoBean.setLoginNameList(LoginNameList);
			briefbatchuserrequestdtoBean.setLoginNameType(LoginNameEnum.LoginId);
			briefbatchuserrequestdtoCall.setData(briefbatchuserrequestdtoBean);
			briefbatchuserrequestdtoCall.callService();

			Logger.verifyEquals(ECode.SUCCESS, briefbatchuserrequestdtoCall.getString("ResponseCode"),
					"验证ResponseCode");
			Logger.verifyEquals("true", briefbatchuserrequestdtoCall.getString("Success"), "验证Success");

			verifyDB(briefbatchuserrequestdtoCall);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_BriefBatchUserRequestDto_003() {
		Logger.start(true, "不传入参数LoginNameType,默认LoginNameType查询");
		try {
			List<String> LoginNameList = new ArrayList<>();
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);
			String loginId = cur.getLoginId();
			LoginNameList.add(loginId);
			briefbatchuserrequestdtoBean.setLoginNameList(LoginNameList);
			briefbatchuserrequestdtoBean.setLoginNameType(null);
			briefbatchuserrequestdtoCall.setData(briefbatchuserrequestdtoBean);
			briefbatchuserrequestdtoCall.callService();

			Logger.verifyEquals(ECode.SUCCESS, briefbatchuserrequestdtoCall.getString("ResponseCode"),
					"验证ResponseCode");
			Logger.verifyEquals("true", briefbatchuserrequestdtoCall.getString("Success"), "验证Success");

			verifyDB(briefbatchuserrequestdtoCall);

		} catch (Exception e) {
			Logger.fail(e);
		}

	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_BriefBatchUserRequestDto_004() {
		Logger.start(true, "不传入参数LoginNameList,失败");
		try {
			briefbatchuserrequestdtoBean.setLoginNameList(null);
			briefbatchuserrequestdtoBean.setLoginNameType(LoginNameEnum.LoginId);
			briefbatchuserrequestdtoCall.setData(briefbatchuserrequestdtoBean);
			briefbatchuserrequestdtoCall.callService();

			Logger.verifyEquals(ECode.BCODE8, briefbatchuserrequestdtoCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyEquals("false", briefbatchuserrequestdtoCall.getString("Success"), "验证Success");
			Logger.verifyIsContains("参数非法",
					briefbatchuserrequestdtoCall.getString("LastErrorMessage"), "验证LastErrorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}

	}

//	@Test
//	@Category({ P1.class })
//	@TestCase
//	public void Tc_BriefBatchUserRequestDto_005() {
//		Logger.start(true, "输入参数超限,失败");
//		try {
//			List<String> LoginNameList = new ArrayList<>();
//			for (int i = 0; i < 102; i++) {
//				CreateUserReq cur = new CreateUserReq();
//				cur = JUserCallService.initCreateUserBean(cur);
//				Integer uid = JUserCallService.createUserCall(cur);
//				String loginId = cur.getLoginId();
//				LoginNameList.add(loginId);
//			}
//
//			briefbatchuserrequestdtoBean.setLoginNameList(LoginNameList);
//			briefbatchuserrequestdtoBean.setLoginNameType(LoginNameEnum.LoginId);
//			briefbatchuserrequestdtoCall.setData(briefbatchuserrequestdtoBean);
//			briefbatchuserrequestdtoCall.callService();
//
//			Logger.verifyEquals("100000", briefbatchuserrequestdtoCall.getString("ResponseCode"), "验证ResponseCode");
//			Logger.verifyEquals("false", briefbatchuserrequestdtoCall.getString("Success"), "验证Success");
//			Logger.verifyEquals("未设置", briefbatchuserrequestdtoCall.getString("Message"), "验证Success");
//
//		} catch (Exception e) {
//			Logger.fail(e);
//		}
//
//	}

}